package it.afs.worklog.application;

import it.afs.utils.PropertyManager;
import it.afs.worklog.persist.DaoFactory;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;

/**
 * @author Fanta
 */
public abstract class BasePage extends WebPage
{

	public BasePage()
	{
		super();
	}
	
	public BasePage(PageParameters parameters) {
		super(parameters);
	}
	
	protected void addComponents()
	{
		add(new Label("page-title", PropertyManager.getValue("application.title")));
		add(new Label("title", PropertyManager.getValue("application.title")));
		add(new Label("version", PropertyManager.getValue("application.version")));
		if(WorkLogSession.getCurrentSession().isLoggedUser())
			add(new Label("user", WorkLogSession.getCurrentSession().getLoggedUser().getNome()));
		else
			add(new Label("user", ""));
	}
	
	protected DaoFactory getFactory()
	{
		return ((HibernateWebRequestCycle)getRequestCycle()).getFactory();
	}
	
	public Link<Void> getHomePageLink()
	{
		return new Link<Void>("back")
		{
			private static final long serialVersionUID = 4580948012908984614L;

			@Override
			public void onClick() {
				setResponsePage(HomePage.class);
			}
		};
	}
}